package 作业;

import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Scanner;

public class PrintCalendar {
	public static int dayNumOfMonth(int year ,int month) {
		int[][]m = {
				{31,28,31,30,31,30,31,31,30,31,30,31},
				{31,29,31,30,31,30,31,31,30,31,30,31}
				};
		return m[isLeapYear(year)][month-1];
	}
	private static int isLeapYear(int year) {
		if(year%400 == 0 || (year % 400 == 0 && year % 100 != 0)) {
			return 1;
		}
		return 0;
	}
	public static void main(String[] args) {
		
		//Calendar calendar = Calendar.getInstance();
		GregorianCalendar g = new GregorianCalendar();
		String months[] = { 
				"Jan", "Feb", "Mar", "Apr", 
				"May", "Jun", "Jul", "Aug",
				"Sep", "Oct", "Nov", "Dec"};
		Scanner s = new Scanner(System.in);
		int year = s.nextInt();
		int month = s.nextInt();
		s.close();
		System.out.println("             "+months[month-1]+"."+year);
		System.out.println("----------------------------------");
		System.out.printf("%4s %4s %4s %4s %4s %4s %4s\n","Sun","Mon","Tues",  "Wed", "Thur",  "Fri",  "Sat");
		g.set(year, month-1, 0);
		int num = g.get(Calendar.DAY_OF_WEEK)%7;
		for(int i=0;i<num;i++) {
			System.out.printf("%4s "," ");
		}
		for(int i=0;i< dayNumOfMonth(year, month);i++,num++) {
			if(num > 0 && num % 7 == 0) System.out.println();

			System.out.printf("%4d ",i+1);
			
		}
	}
}
